package com.tool.controller;

import com.tool.exception.BaseException;
import com.tool.exception.LoginFailedException;
import com.tool.exception.UserNotLoginException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 酒徒
 * @Version 1.0
 * @data 2024/1/22 19:47
 */
@RestController
@RequestMapping("/exception")
public class TestController {
    /**
     * 抛出LoginFailedException，上抛给BaseException, 由GlobalExceptionHandler处理
     */
    @GetMapping("/test1")
    public void testException1() {
        throw new LoginFailedException("登录失败");
    }

    /**
     * 与抛出LoginFailedException类似
     */
    @GetMapping("/test2")
    public void testException2() {
        throw new UserNotLoginException("用户不存在");
    }

    /**
     * 不在处理器中的异常，GlobalExceptionHandler不接受
     */
    @GetMapping("/test3")
    public void testException3() {
        try {
            throw new Exception();
        } catch (Exception e) {
            throw new BaseException(e.getMessage());
        }
    }
}
